home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / snip9_91.arc / DSPCLOCK.C < prev    next >
C/C++ Source or Header  |  1991-09-17  |  3KB  |  84 lines

  1. // public domain TSR clock code. By Michelangelo Jones, 1:141/575 or
  2. // 1:1/124. Very little support available; this is a quick hack, not
  3. // an example of the best way to write a clock TSR! Use at own risk.
  4. // Runs under TC++/BC++. Your mileage may vary.
  5.  
  6. #ifndef __HUGE__
  7. #error "Must be compiled using HUGE model-- for now"
  8. #endif
  9.  
  10. #include <dos.h>
  11.  
  12. extern unsigned _heaplen = 0;
  13. extern unsigned _stklen = 512;
  14.  
  15. static char * screenbase =
  16.            (char *)                  MK_FP (0xb800, 0); // change for mono
  17. static const long int * volatile ticks =                // to 0xb000, 0
  18.            (long int * volatile)     MK_FP (0, 0x046c);
  19.  
  20. int calls, lastsec, lastmin, lasthr;
  21. const double tps = 18.20648;          // found by experimentation!
  22.  
  23. void interrupt (*oldhandler)(void);
  24.  
  25. void displayclock (void)
  26. {
  27.     char *moveinto = screenbase + 300;
  28.     char *initwith = "      :     :       ";
  29.  
  30. // NOTE: This initializer only works because the attribute I want for the
  31. //       clock HAPPENS to be the same as the ASCII value for the SPACE char!
  32. //       Modify every alternate character if you want some other attribute.
  33.  
  34.     while (*initwith)
  35.         *moveinto++ = *initwith++;
  36.     lastsec = -1;
  37.     lastmin = -1;
  38.     lasthr  = -1;
  39.     calls   = 20;
  40. }
  41.  
  42. void interrupt clockproc(void)
  43. {
  44.     static long seconds;
  45.  
  46.     if (calls < 17)
  47.         calls++;
  48.     else
  49.     {
  50.         seconds = (long) ((double) *ticks / tps);
  51.         if (screenbase[301] != ' ') // if the attribute has changed,
  52.             displayclock();         // the screen scrolled, so update.
  53.         if (seconds % 60 != lastsec)
  54.         {
  55.             lastsec = seconds % 60;
  56.             calls = 0;
  57.             screenbase[314] = (char) (lastsec/10) + 48;
  58.             screenbase[316] = (char) (lastsec%10) + 48;
  59.             if ((! lastsec) || (lastmin < 0))
  60.             {
  61.                 lastmin = (seconds % 3600) / 60;
  62.                 screenbase[308] = (char) (lastmin/10) + 48;
  63.                 screenbase[310] = (char) (lastmin%10) + 48;
  64.                 if ((! lastmin) || (lasthr < 0))
  65.                 {
  66.                     lasthr = ((seconds % 86400L) / 3600L);
  67.                     screenbase[302] = (char) (lasthr/10) + 48;
  68.                     screenbase[304] = (char) (lasthr%10) + 48;
  69.                 }
  70.             }
  71.         }
  72.     }
  73.     oldhandler ();
  74. }
  75.  
  76. void main(void)
  77.  
  78. {
  79.     oldhandler = getvect (0x1c);
  80.     displayclock();
  81.     setvect (0x1c, clockproc);
  82.     keep (0, (_SS + (_SP/16) - _psp));
  83. }
  84.